/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.AlbumCategory;
import com.startup.musicstore.model.MarketingInformation;
import com.startup.musicstore.model.Review;
import com.startup.musicstore.services.AlbumRatingService;
import com.startup.musicstore.services.crud.AlbumCategoryCrudService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author linda
 */
@Service("albumRatingService")
@Transactional
public class AlbumRatingServiceImpl implements AlbumRatingService {

    @Autowired
    private AlbumCategoryCrudService albumCategoryCrudService;
    
    @Override
    public int getAlbumRating(Long albumID) {
        int rating = 0;
        List<AlbumCategory> categories = albumCategoryCrudService.findAll();
        
        for(int b =0; categories.size() > 0; b++)
        {
            AlbumCategory cat = categories.get(b);
            List<Album> albums = cat.getAlbums();
            for(int i =0; albums.size()>i; i++)
            {
                Album album = albums.get(i);
                if(album.getId() == albumID)
                {
                    rating = album.getMarketingInfo().getReview().getRating(); 
                }
            }
        }
        
        return rating;
       
    }
    
}
